//
//  vedioSelect.swift
//  swifttest1
//
//  Created by kologe on 2024/9/9.
//

import SwiftUI
import NetAction


struct ScanList: View {
    @State private var isButtonTapped = false
    @State var fileName:String = ""
    @ObservedObject var listDataSource:KzMutableArray<Scan> = terminal_list
    @ObservedObject var hostName = NetMessage.shared()
    
    var body: some View {
            VStack {
                Text(NSLocalizedString("scanStatus", comment: "default")).titleStyle()
                Spacer()
                if !isButtonTapped{
                    HStack{
                        Spacer()
                        if #available(macOS 12.0, *) {
                            Text("\(NSLocalizedString("localTerminal", comment: "default")): ").padding(5).foregroundStyle(kcolors.textColor)
                                .frame(width:100,height: 20,alignment: Alignment.center)
                        } else {
                            // Fallback on earlier versions
                            Text("\(NSLocalizedString("localTerminal", comment: "default")): ").padding(5)
                                .frame(width:100,height: 20,alignment: Alignment.center)
                        }
                        
                        TextEditor(text: $hostName.hostName)
                            .frame(width:300,height: 20,alignment: Alignment.center)
                            
                        Spacer()
                    }.opacity(!isButtonTapped ? 1.0 : 0.0)
                        .scaleEffect(!isButtonTapped ? 1.0 : 0.5)
                    
                    Button(action: {
                        terminal_list.removeAllObjects()//清除所有的数据
                        Scan.sendData()
                        
                        withAnimation(.smooth) {
                            isButtonTapped.toggle()
                        }
                        
//                        let msg = "ffffffffajfdlkjalkfjadsfjlajf;afkghajh afhdasfh afdh asfadsfadlasjh jhafkj var view = WarnText(textStr: msg,size:NSMakeSize(450, 200));let id = Cal.hashOfString(str: msg)view.winId = id"
//                        var view = WarnText(textStr: msg,size:NSMakeSize(450, 200));
//                        let id = Cal.hashOfString(str: msg)
//                        view.winId = id
//                      
//                        WindowDelegate.openWindow(view: view, title: "warn", size: NSMakeSize(450, 200), id: id)
                    }, label: {
                        Text(    NSLocalizedString("scanTerminal", comment: "")  ).frame(width: 80)
                    })
                    .nomalStyle()
                    .frame(width: 100).opacity(!isButtonTapped ? 1.0 : 0.0)
                    .scaleEffect(!isButtonTapped ? 1.0 : 0.5)
                }else{
                    ListView(dataSource: $listDataSource.array, isButtonTapped: $isButtonTapped).frame(maxWidth: .infinity)
                        .opacity(isButtonTapped ? 1.0 : 0.0)
                        .scaleEffect(isButtonTapped ? 1.0 : 0.5)
                }
                
                Spacer()
                
            }
            
    }
    
    
}

#Preview {
    ScanList()
}
